
class FabricEventBus {
    constructor (
        public id: string
    ) {
    }
    public events: {
        [key: string]: FabricEventType
    } = {
        "_fabric_event_bus_emit": {
            handlers: {
                "_handle": (event: FabricEvent): void => {
                    const handlers: FabricEventHandlerMap = this.events[event.type]!.handlers;
                    for (let handler in handlers) {
                        handlers[handler]({
                            type: event.type,
                            data: event.data
                        });
                    }
                }
            }
        }
    }
    public emit<T>(type: string, data: FabricEventData<T>): boolean {
        if (this.events[type]) {
            const handlers: FabricEventHandlerMap = this.events["_fabric_event_bus_emit"]!.handlers
            for (let handler in handlers) {
                handlers[handler]({
                    type,
                    data
                });
            }
            return true;
        } else {
            return false;
        }
    }
    public listen(eventType: string, id: string): Function {
        return (value: FabricEventHandler, context: {
            kind: "method";
            name: string | symbol;
            static: boolean;
            private: boolean;
            access: { get: () => unknown };
            addInitializer(initializer: () => void): void;
        }): Function => {
            this.events[eventType].handlers[id] = value;
            return value;
        }
    }
}

const eventBus = new FabricEventBus("test");
eventBus.events["test"] = {
    handlers: {}
}

type a = ClassDecorator
function test (event: FabricEvent): void {
    console.log("测试");
}





interface FabricEvent<T = any> {
    type: string,
    data: FabricEventData<T>
}
type FabricEventData<T = any> = T
type FabricEventHandler = (event: FabricEvent) => void
interface FabricEventHandlerMap {
    [key: string]: FabricEventHandler
}
interface FabricEventType<T = any> {
    handlers: FabricEventHandlerMap
}